//
//  CATransitionAnimationViewController.m
//  iOSHeartAnimation
//
//  Created by ddy on 2018/7/27.
//  Copyright © 2018年 ddy. All rights reserved.
//
//转场动画是一种显示样式向另一种显示样式过渡的效果，不太需要脑子就能制作出酷炫的效果，系统给出的效果也很多，不过谨慎使用私有API，防止被拒的悲剧。创建转场动画真的很简单：

//创建转场动画
//设置转场类型type，以及自类型subtype（也就是转场方向，不是所有的效果都有子类型）及其他属性。
//设置新的显示效果后，添加动画到图层。

#import "CATransitionAnimationViewController.h"

@interface CATransitionAnimationViewController ()
{
    int _transtionIndex;
    CALayer *_layer;
}
@end
static NSString * const kTransitionKey = @"kTransitionKey";
@implementation CATransitionAnimationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"转场动画";
    //创建layer
    _layer = [CALayer layer];
    _layer.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width-180)*0.5, 100, 180, 180);
    [self.view.layer addSublayer:_layer];
    ///转场动画
    [self transitionAnimation];
    
}
#pragma mark --- 转场动画
- (void)transitionAnimation {
    CATransition *transition = [CATransition animation];
    transition.type = @"rippleEffect";
    transition.subtype = kCATransitionFromRight;
    transition.duration = 1.0;
    _transtionIndex++;
    if (_transtionIndex > 4) {
        _transtionIndex = 1;
    }
    _layer.contents = (__bridge id)[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",_transtionIndex]].CGImage;
    [_layer addAnimation:transition forKey:kTransitionKey];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self transitionAnimation];
}






















@end
